home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / publist.fr_ / publist.fr
Text File  |  1995-02-12  |  3KB  |  118 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSelectPublisher 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Select Publisher"
  5.    ClientHeight    =   3150
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1530
  8.    ClientWidth     =   4995
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   1
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   3555
  19.    Left            =   1035
  20.    LinkTopic       =   "Form2"
  21.    ScaleHeight     =   3150
  22.    ScaleWidth      =   4995
  23.    Top             =   1185
  24.    Width           =   5115
  25.    Begin VB.CommandButton cmdCancel 
  26.       Cancel          =   -1  'True
  27.       Caption         =   "Cancel"
  28.       Height          =   495
  29.       Left            =   2820
  30.       TabIndex        =   2
  31.       Top             =   2460
  32.       Width           =   1215
  33.    End
  34.    Begin VB.ListBox List1 
  35.       Height          =   1980
  36.       Left            =   360
  37.       Sorted          =   -1  'True
  38.       TabIndex        =   1
  39.       Top             =   180
  40.       Width           =   4215
  41.    End
  42.    Begin VB.CommandButton cmdOK 
  43.       Caption         =   "OK"
  44.       Default         =   -1  'True
  45.       Height          =   495
  46.       Left            =   1020
  47.       TabIndex        =   0
  48.       Top             =   2460
  49.       Width           =   1215
  50.    End
  51. End
  52. Attribute VB_Name = "frmSelectPublisher"
  53. Attribute VB_Creatable = False
  54. Attribute VB_Exposed = False
  55. Option Explicit
  56. Const DATABASE_NAME = "D:\VB4\BIBLIO.MDB"
  57.  
  58. Private Sub Form_Load()
  59.     Dim db As Database
  60.     Dim rs As Recordset
  61.     Dim sql As String
  62.     
  63.     On Error GoTo LoadError
  64.     
  65.     ' Open the database and create a recordset with a list of publishers.
  66.     Set db = DBEngine.Workspaces(0).OpenDatabase(DATABASE_NAME)
  67.     sql = "SELECT [PubID], [Company Name] FROM [Publishers]"
  68.     Set rs = db.OpenRecordset(sql)
  69.     
  70.     ' Use the recordset to fill the publishers list.
  71.     If rs.RecordCount > 0 Then
  72.         FillList rs
  73.     Else
  74.         MsgBox "There are no publishers in the database.", vbCritical
  75.         End
  76.     End If
  77. Exit Sub
  78. LoadError:
  79.     MsgBox Error$, vbCritical
  80. End
  81. End Sub
  82. Private Sub FillList(rs As Recordset)
  83.  
  84.     ' Use the recordset passed as the argument to fill the publishers
  85.     ' list box. Use the publisher name as the text for each item and
  86.     ' the PubID as the ItemData.
  87.     rs.MoveFirst
  88.     Do
  89.         If Not IsNull(rs![Company Name]) Then List1 _
  90.             .AddItem rs![Company Name] Else List1.AddItem ""
  91.         List1.ItemData(List1.NewIndex) = rs![PubID]
  92.         rs.MoveNext
  93.     Loop While Not rs.EOF
  94. End Sub
  95.  
  96. Private Sub cmdOK_Click()
  97.  
  98.     ' If the user has selected a publisher, set the frmMain variable
  99.     ' to the PubID and hide this form.
  100.     If List1.ListIndex > -1 Then
  101.         frmMain.SelectedPubID = List1.ItemData(List1.ListIndex)
  102.         Hide
  103.     Else
  104.         MsgBox "You have not selected a publisher", vbExclamation
  105.     End If
  106. End Sub
  107. Private Sub List1_DblClick()
  108.     cmdOK_Click
  109. End Sub
  110. Private Sub cmdCancel_Click()
  111.  
  112.     ' Set the frmMain variable to 0 to indicate that the user cancelled
  113.     ' without selecting a publisher.
  114.     frmMain.SelectedPubID = 0
  115.     Hide
  116. End Sub
  117.  
  118.